package dormouse.vfs.metadata;

import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;

import org.apache.commons.vfs2.FileObject;

/**
 *
 */
public class MetadataViewerFactory {
	
	static Map<String, IMetadataViewer> viewerMap = new HashMap<String, IMetadataViewer>();
	
	static {
		ServiceLoader<IMetadataViewer> loader = ServiceLoader.<IMetadataViewer>load(IMetadataViewer.class);
		for(IMetadataViewer viewer : loader){
			for(String ext : viewer.getExtensions()){
				viewerMap.put(ext, viewer);
			}
		}
		
	}
	
	
	public static IMetadataViewer getInstance(FileObject file){
		IMetadataViewer viewer = viewerMap.get(file.getName().getExtension());
		if(viewer == null){
			viewer = viewerMap.get(IMetadataViewer.DEFAULT);
		}
		
		return viewer;
	}

}
